package me.ingxin.android.sample.lego.handler;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;

import me.ingxin.android.router.annotaions.Route;
import me.ingxin.android.router.route.Request;
import me.ingxin.android.router.route.Result;
import me.ingxin.android.router.route.RouteHandler;

/**
 * Created by ingxin on 2022/4/27
 */
@Route(path = "/handler/test2", hold = true)
public class Test2Handler extends RouteHandler {

    @Override
    public void handle(@NonNull Context context, @NonNull Request request) {
        int a = request.getInt("a",0);
        int b = request.getInt("b",0);
        Toast.makeText(context, "Test2Handler：IO线程计算" + a + "+" + b + "=?", Toast.LENGTH_SHORT).show();
        new Thread(() -> {
            try {
                Thread.sleep(3000);
                Result result = new Result();
                result.putInt("res", a + b);
                setResult(result);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

    }

    @Override
    public void onRelease() {
        Log.d("Lego:Router", "释放Test2Handler");
    }


}
